<?

if ($DATA['component']['id']) {

	// list editor
	
	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";

	$_param			= 'edit';				//	ID param name in the URL, used here & @ template
	$_values			= array('title', 'anons', 'body');	// which fields are stored in language variations
	

	$s = array_extend( array('path' => 'article', 'w' => 128, 'h' => 96, 'param' => 'id'), $DATA['component']['settings']);

	$s['path'] = createdir(FP_UPLOAD_PATH.$s['path'].'/');
	$s['h'] = (int)$s['h'];
	$s['w'] = (int)$s['w'];


	$DATA['today'] = parse_today();
	
	
	if (($a = (int)param('edit')) && ($DATA['object'] = datafetch('db_item', tb('data'), "$_crit AND id=$a"))) {
		
		if (!$DATA['object']['date_create'])
			$DATA['object']['date_create'] = $DATA['today']['full'];

		$DATA['object']['date_visible'] = format_simple_date( $DATA['object']['date_create'] );
		
	
		switch (action(array('editor_save', 'editor_save_enable'))) {
		
			case 'editor_save_enable':
			
				$DATA['object']['attr'] |= AA_VISIBLE;
			
			case 'editor_save':

				$_record = array('id_data' => $_id_meta, 'id_parent' => $a);
				$temp = array();
	
				foreach($DATA['langs'] as $lang) {
				
					foreach($_values as $name) {
					
						$t = postdata($name);
						$temp[] = array_merge($_record, array('name' => $name, 'value' => $t[$lang['text']], 'assoc' => $lang['text']));
				
					}
	
				}

				dataset('db_delete', tb('data'), "id_data=$_id_meta AND id_parent=$a");
				dataset('db_insert', tb('data'), $temp);

				$t = ($temp = trim($_POST['title'][LANG_DEF])) ? $temp : $DATA['object']['title'];
				$u = trim(postdata('url'));
				$d = parse_date(trim(postdata('date_create')));
				dataset('db_update', tb('data'), array('name' => $t, 'text' => $u, 'attr' => $DATA['object']['attr'], 'date_create' => $d['full']), "id=$a");
				

				takeImage('image', $s['w'], $s['h'], "$s[path]$a");

				header("Location: "._transformURL($CURRENT->url, array('remove_param' => $_param)));
				exit;
		
				break;
		}
	
	
	
	
	
		foreach($DATA['langs'] as $lang)
			$DATA['object']['data'][$lang['text']] = datafetch_array('meta', $_id_meta, $a, $lang['text']);
			
		if ($f = isImage($s['path'], $a))
			$DATA['object']['image'] = $s['path'].$f;

	}
	


	return false;
	
} else exit;

?>
